package com.tokenplus.thai.aviewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.tokenplus.thai.adata.coupons.ReqCouponUse
import com.tokenplus.thai.adata.coupons.ReqCouponVerify
import com.tokenplus.thai.adata.coupons.RevCouponItem
import com.tokenplus.thai.base.BaseViewModel
import com.tokenplus.thai.anetwork.ApiUserReposity
import com.tokenplus.thai.data.ReqBase

class CouponsViewModel : BaseViewModel() {

    val mCouponList = mutableListOf<RevCouponItem>()

    //////////////////////////////////////////
    private val mGetCouponsLiveData = MutableLiveData<ReqBase>()

    val onGetCouponsLiveData =
        Transformations.switchMap(mGetCouponsLiveData) { query ->
            ApiUserReposity.getCoupons(this, query)
        }

    fun getCoupons(reqBase: ReqBase) {
        mGetCouponsLiveData.value = reqBase
    }

    //////////////////////////////////////////
    private val mCouponUseLiveData = MutableLiveData<ReqCouponUse>()

    val onCouponUseLiveData =
        Transformations.switchMap(mCouponUseLiveData) { query ->
            ApiUserReposity.couponUse(this, query)
        }

    fun couponUse(reqCouponUse: ReqCouponUse) {
        mCouponUseLiveData.value = reqCouponUse
    }

    //////////////////////////////////////////
    private val mCouponVerifyLiveData = MutableLiveData<ReqCouponVerify>()

    val onCouponVerifyLiveData =
        Transformations.switchMap(mCouponVerifyLiveData) { query ->
            ApiUserReposity.couponVerify(this, query)
        }

    fun couponVerify(reqCouponVerify: ReqCouponVerify) {
        mCouponVerifyLiveData.value = reqCouponVerify
    }
}